]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
NotificationDaemon: improve associating sources with applications
authorGiovanni Campagna <gcampagna@src.gnome.org>
Sun, 4 Nov 2012 00:53:43 +0000 (01:53 +0100)
committerGiovanni Campagna <gcampagna@src.gnome.org>
Thu, 31 Jan 2013 12:20:08 +0000 (13:20 +0100)
Try harder to find a ShellApp for a notification source, by looking
at the PID, tray icon wm_class and desktop-entry libnotify hint.

https://bugzilla.gnome.org/show_bug.cgi?id=685926

js/ui/notificationDaemon.js

index fa1d7157b97607d3c1b2f1ab46d3b005a4f1907b..e353d8d15025131c5dbf02e2f67f82dce84989fe 100644 (file)
@@ -213,7 +213,7 @@ const NotificationDaemon = new Lang.Class({
             }
         }
 
-        let source = new Source(title, pid, sender, trayIcon);
+        let source = new Source(title, pid, sender, trayIcon, ndata ? ndata.hints['desktop-entry'] : null);
         source.setTransient(isForTransientNotification);
 
         if (!isForTransientNotification) {
@@ -515,12 +515,22 @@ const Source = new Lang.Class({
     Name: 'NotificationDaemonSource',
     Extends: MessageTray.Source,
 
-    _init: function(title, pid, sender, trayIcon) {
+    _init: function(title, pid, sender, trayIcon, appId) {
+        // Need to set the app before chaining up, so
+        // methods called from the parent constructor can find it
+        this.trayIcon = trayIcon;
+        this.pid = pid;
+        this.app = this._getApp(appId);
+
         this.parent(title);
 
         this.initialTitle = title;
 
-        this.pid = pid;
+        if (this.app)
+            this.title = this.app.get_name();
+        else
+            this.useNotificationIcon = true;
+
         if (sender)
             this._nameWatcherId = Gio.DBus.session.watch_name(sender,
                                                               Gio.BusNameWatcherFlags.NONE,
@@ -529,16 +539,10 @@ const Source = new Lang.Class({
         else
             this._nameWatcherId = 0;
 
-        this._setApp();
-        if (this.app)
-            this.title = this.app.get_name();
-        else
-            this.useNotificationIcon = true;
-
-        this.trayIcon = trayIcon;
         if (this.trayIcon) {
-           this._setSummaryIcon(this.trayIcon);
-           this.useNotificationIcon = false;
+            // Try again finding the app, using the WM_CLASS from the tray icon
+            this._setSummaryIcon(this.trayIcon);
+            this.useNotificationIcon = false;
         }
     },
 
@@ -588,7 +592,7 @@ const Source = new Lang.Class({
         return true;
     },
 
-    _getApp: function() {
+    _getApp: function(appId) {
         let app;
 
         app = Shell.WindowTracker.get_default().get_app_from_pid(this.pid);
@@ -596,7 +600,13 @@ const Source = new Lang.Class({
             return app;
 
         if (this.trayIcon) {
-            app = Shell.AppSystem.get_default().lookup_wmclass(this.trayIcon.wmclass);
+            app = Shell.AppSystem.get_default().lookup_wmclass(this.trayIcon.wm_class);
+            if (app != null)
+                return app;
+        }
+
+        if (appId) {
+            app = Shell.AppSystem.get_default().lookup_app(appId + '.desktop');
             if (app != null)
                 return app;
         }
@@ -604,11 +614,11 @@ const Source = new Lang.Class({
         return null;
     },
 
-    _setApp: function() {
+    _setApp: function(appId) {
         if (this.app)
             return;
 
-        this.app = this._getApp();
+        this.app = this._getApp(appId);
         if (!this.app)
             return;